<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;

$this->title = 'intention';
?>
<style>
	.add_department .box-footer{text-align:center;border-top:0;}
	.add_department .box-footer button{width:200px;}
</style>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box-header"><h2 class="box-title">客户意向记录</div>
			<div class="box-body add_department">
				<?php $form = ActiveForm::begin(['action' => ['customer/intention', 'uid' => $uid], 'method' => 'post']);?>
					<div class="box-body">
						<div class="form-group">
							<label>客户姓名</label><br/>
							<?= $username ?>
						</div>
						<div class="form-group">
							<label>接待人</label>
							<select class="form-control depart" style="width:30%;">
								<option>选择部门</option>
								<?php foreach($depart as $key=>$val): ?>
									<option value="<?= $key ?>"><?= $val ?></option>
								<?php endforeach;?>
							</select>
							<select class="form-control employees" name="trans_user" style="width:30%;">
								<option value="">选择接待人</option>
							</select>
							<?=Html::error($model, 'trans_user', ['style' => 'color:red'])?>
						</div>
						<div class="form-group">
							<label>意向产品</label>
							<input type='hidden' name="uid" value="<?= $uid ?>" />
							<?=Html::dropDownList('pid', $model->pid, $product, ['class'=>'form-control']);?>
							<?=Html::error($model, 'pid', ['style' => 'color:red'])?>
						</div>
						<div class="form-group">
							<label>认可度</label>
							<?=Html::textInput('agreed', $model->agreed, ['class' => 'form-control', 'placeholder' => '客户产品认可度']);?>
							<?=Html::error($model, 'agreed', ['style' => 'color:red'])?>
						</div>
						<div class="form-group">
							<label>疑惑点</label>
							<?=Html::textarea('confusion', $model->confusion, ['class' => 'form-control', 'placeholder' => '客户疑惑点']);?>
							<?=Html::error($model, 'confusion', ['style' => 'color:red'])?>
						</div>
						<div class="form-group">
							<label>考虑因素</label>
							<?=Html::textarea('consider', $model->consider, ['class' => 'form-control', 'placeholder' => '客户考虑因素']);?>
							<?=Html::error($model, 'consider', ['style' => 'color:red'])?>
						</div>
			            <div class="form-group">
			              <label>备注信息</label>
							<?=Html::textarea('remark', $model->remark, ['class' => 'form-control', 'placeholder' => '备注信息']);?>
							<?=Html::error($model, 'remark', ['style' => 'color:red'])?>
			            </div>
					</div>
					<div class="box-footer">
						<button type="submit" class="btn btn-primary">确定</button>
						<button type="submit" class="btn btn-warning back">返回</button>
					</div>
				<?php ActiveForm::end();?>
			</div>
		</div>
	</div>
</section>

<script src="js/jquery.js"></script>
<script>
	$(".depart").change(function(){
		var did = $(this).val();
		var url = "<?= Url::toRoute('customer/getemployee')?>";
		var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
		$.ajax({
			url:url,
			type:'GET',
			dataType:'json',
			data: {
				did:did,
				_csrf:_csrf
			},
			success: function(json){
				var html = "";
				if (json.flag) {
		           	$.each(json.data, function (n, value) {
		           		html += "<option value='"+n+"'>"+value+"</option>";
		            });
				} else {
					html = "<option value=''>部门暂无员工</option>";
				}
				$(".employees").html(html);
			},
			error:function(){
				alert('网络忙');
			}
		});	
	});
	/*返回*/
	$(".back").click(function(){
		location.href = history.go(-1);
	});
</script>